package cn.zbox.dubbo;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;

import cn.zbox.dubbo.action.GreetingServiceConsumer;

public class ConsumerBootstrap {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
		context.start();
		GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class);
		String hello = greetingServiceConsumer.doSayHello("configuration");
		context.close();
		System.out.println("result: " + hello);
	}

	@Configuration
	@EnableDubbo(scanBasePackages = "cn.zbox.dubbo.action")
	@PropertySource("classpath:/spring/dubbo-consumer.properties")
	@ComponentScan(value = { "cn.zbox.dubbo.action" })
	static class ConsumerConfiguration {
		/*
		 * annotation方式配置。已通过dubbo-comsumer.properties配置，所以注释掉注解配置
		@Bean
		public ApplicationConfig applicationConfig() {
			ApplicationConfig applicationConfig = new ApplicationConfig();
			applicationConfig.setName("dubbo-annotation-consumer");
			return applicationConfig;
		}

		@Bean
		public ConsumerConfig consumerConfig() {
			ConsumerConfig consumerConfig = new ConsumerConfig();
			consumerConfig.setTimeout(3000);
			return consumerConfig;
		}

		@Bean
		public RegistryConfig registryConfig() {
			RegistryConfig registryConfig = new RegistryConfig();
			registryConfig.setProtocol("zookeeper");
			registryConfig.setAddress("localhost");
			registryConfig.setPort(2181);
			return registryConfig;
		}*/
	}
}
